using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Elementum
{
    public abstract class Transition
    {
        public int _counter;
        protected int _start;
        protected int _end;
        protected Stage _stage;

        public delegate void TransitionDoneActionHandler();
        public event TransitionDoneActionHandler TransitionDoneAction;

        public Transition(int start, int end) {
            if (end <= start)
                throw new Exception("End most bigger than start!!");
            _stage = null;
            _counter = 0;
            _start = start;
            _end = end;
        }

        public void Register(Stage stage){
            this._stage = stage;
            _stage.TransitionList.Add(this);
        }

        public virtual void OnDraw(SpriteBatch spriteBatch)
        {
            if (_counter == _end)
            {
                TransitionDone();
            }
        }

        protected virtual void OnTransition() {
           
        }

        protected virtual void TransitionDone() {
            
            if (TransitionDoneAction != null)
                TransitionDoneAction();

        }

        public virtual void Update()
        {
            if (_counter >= _start && _counter <= _end)
                if (_stage != null)
                    OnTransition();
            if (_counter > _end)
            {
                TransitionDone();
            }
            if (_counter <= _end)
                _counter++;
        }
    }
}
